home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 10, No. 02 (1989-02)(MicroSPARC)(Side A)[a].zip / Nibble Volume 10, No. 02 (1989-02)(MicroSPARC)(Side A)[a].po / SHAPE.LIB.B.S < prev    next >
Text File  |  1996-12-24  |  31KB  |  1,213 lines

  1. ********************************
  2. *                              *
  3. *            PARTB             *
  4. *   Machine Language Routines  *
  5. *      for Table.Librarian     *
  6. *       by James Brodsky       *
  7. *                              *
  8. *      Copyright (c) 1987      *
  9. *      By Microsparc, Inc.     *
  10. *                              *
  11. *      Merlin Pro Assembler    *
  12. *                              *
  13. ********************************
  14.  
  15. *------------------------------------
  16. * Zero page memory locations:
  17. *------------------------------------
  18.  
  19. PTR2      EQU 0          ;general purpose pointer
  20. SHAPE1    EQU 2          ;pointer to main table
  21. END1      EQU 4          ;end of main table
  22. EFLG      EQU 6          ;set if [ESC] pressed
  23. MAX       EQU 7          ;max string len for input
  24. PTR       EQU 6          ;general use temporary pointer
  25. PTR1      EQU 8          ;general use temporary pointer
  26. CH        EQU $24        ;40 column H cursor
  27. CV        EQU $25        ;V tab position
  28. A1L       EQU $3C
  29. A1H       EQU $3D
  30. A2L       EQU $3E
  31. A2H       EQU $3F
  32. A4L       EQU $42
  33. A4H       EQU $43
  34. LINNUM    EQU $50
  35. TXTTAB    EQU $67
  36. LOMEM     EQU $69
  37. ARYTAB    EQU $6B
  38. STREND    EQU $6D
  39. HIGHDS    EQU $94
  40. HIGHTR    EQU $96
  41. LOWTR     EQU $9B
  42. DSCTMP    EQU $9D
  43. PRGEND    EQU $AF
  44. ERRFLG    EQU $D8
  45. SHAPE     EQU $E8        ;pointer to shape table
  46.  
  47. *------------------------------------
  48. * Hardware addresses:
  49. *------------------------------------
  50.  
  51. BUFFER    EQU $200
  52. AMPV      EQU $3F5
  53.  
  54. *------------------------------------
  55. * BASIC and MONITOR routines:
  56. *------------------------------------
  57.  
  58. CHRGET    EQU $B1
  59. CHRGOT    EQU $B7
  60. MOVEUP    EQU $D39A
  61. GDBUFS    EQU $D539
  62. FRMNUM    EQU $DD67
  63. CHKSTR    EQU $DD6C
  64. CHKCOM    EQU $DEBE
  65. SYNCHR    EQU $DEC0
  66. SYNERR    EQU $DEC9
  67. PTRGET    EQU $DFE3
  68. STRSPA    EQU $E3DD
  69. MOVSTR    EQU $E5E2
  70. GETBYT    EQU $E6F8
  71. GETADR    EQU $E752
  72. CLREOL    EQU $FC9C
  73. RDKEY     EQU $FD0C
  74. COUT      EQU $FDED
  75. COUT1     EQU $FDF0
  76. MOVE      EQU $FE2C
  77.  
  78.  
  79.           ORG $4000
  80.  
  81. *--------------------------------------------
  82. *
  83. *  The following code is run once at $4000
  84. *   to embed the ML routines into the main
  85. *   Applesoft program.
  86. *  The code between INSTALL and PGMSTART
  87. *   is then abandoned.
  88. *
  89. *--------------------------------------------
  90.  
  91. INSTALL                  ;embed code into Applesoft
  92.           LDY #0
  93.           LDA PRGEND+1
  94.           LDX PRGEND
  95.           STA A4H
  96.           STX A4L
  97.           LDA #>END
  98.           LDX #<END
  99.           STA A2H
  100.           STX A2L
  101.           LDA #>PGMSTART
  102.           LDX #<PGMSTART
  103.           STA A1H
  104.           STX A1L
  105.           JSR MOVE
  106.           CLC
  107.           LDA #<END-PGMSTART
  108.           ADC PRGEND
  109.           STA PRGEND
  110.           STA LOMEM
  111.           STA ARYTAB
  112.           STA STREND
  113.           LDA #>END-PGMSTART
  114.           ADC PRGEND+1
  115.           STA PRGEND+1
  116.           STA LOMEM+1
  117.           STA ARYTAB+1
  118.           STA STREND+1
  119.           JMP $3D0
  120.  
  121. *-------------------------------------------------
  122. *
  123. *  The following section of code is run once
  124. *   each time the Applesoft program is loaded.
  125. *  It moves the embedded ML routines to start
  126. *   at $C03 and restores the Applesoft
  127. *   end-of-program pointers to the end of the
  128. *   Applesoft code.
  129. *  The area where the ML routines were embedded
  130. *   can then be used by Applesoft for
  131. *   variable storage.
  132. *  NOTE that if the Applesoft program is stopped
  133. *   and saved after this section has been run,
  134. *   the ML routines will no longer be saved
  135. *   with it.
  136. *
  137. *-------------------------------------------------
  138.  
  139. PGMSTART  LDY #0         ;move code to page $C
  140.           LDA PRGEND
  141.           STA A2L
  142.           SEC
  143.           SBC #<END-SEGMENT
  144.           STA A1L
  145.           LDA PRGEND+1
  146.           STA A2H
  147.           SBC #>END-SEGMENT
  148.           STA A1H
  149.           SEC
  150.           LDA PRGEND
  151.           SBC #<END-PGMSTART
  152.           STA PRGEND
  153.           STA LOMEM
  154.           STA ARYTAB
  155.           STA STREND
  156.           LDA PRGEND+1
  157.           SBC #>END-PGMSTART
  158.           STA PRGEND+1
  159.           STA LOMEM+1
  160.           STA ARYTAB+1
  161.           STA STREND+1
  162.           LDA #<VAREND
  163.           LDX #>VAREND
  164.           STA A4L
  165.           STX A4H
  166.           JSR MOVE       ;use monitor to move code
  167.  
  168. SETAMPV   LDY #1         ;save old amper vector
  169. :1        LDA AMPV+1,Y
  170.           STA STASH,Y
  171.           DEY
  172.           BPL :1
  173.  
  174.           LDA #>START    ;setup our amper vector
  175.           LDY #<START
  176.           STA AMPV+2
  177.           STY AMPV+1
  178.           LDA #$4C
  179.           STA AMPV
  180.           RTS            ;return to BASIC after setup
  181.  
  182.  
  183. *----------------------------------------------------
  184. *  Program variable storage area:
  185. *----------------------------------------------------
  186.  
  187.           DUM $C03
  188.  
  189. STASH     DS 2           ;save old amper vector here
  190. MODE      DS 1
  191. STASH1    DS 2           ;[ESC] msg... WARNING -
  192.                          ; STASH1 actually extends
  193.                          ; over 20 bytes and overwrites
  194.                          ; remaining variables in this
  195.                          ; section.
  196. ADRSAVE1  DS 2           ;start address of shape
  197. ADREND1   DS 2           ;end address of shape
  198. LENGTH1   DS 2           ;length of shape
  199. ADRSAVE2  DS 2           ;start address of shape to move
  200. ADREND2   DS 2           ;end address of shape to move
  201. LENGTH2   DS 2           ;length of shape to move
  202. FROMNUM   DS 1           ;number ofshape to move
  203. TONUM     DS 1           ;number of location to move to
  204. SHAPES    DS 1           ;number shapes in table
  205. COUNTER   DS 1
  206. TEMP      DS 3
  207.  
  208. VAREND    DEND
  209.  
  210. *---------------------------------------------------
  211. *
  212. *  Start of ML code which was embedded in
  213. *   Applesoft program and has been moved to its
  214. *   running location.
  215. *  First routine saves old Ampersand vector and
  216. *   points Ampersand vector to the main
  217. *   entry point, START, then exits to BASIC.
  218. *
  219. *---------------------------------------------------
  220.  
  221. SEGMENT
  222.  
  223.           ORG VAREND
  224.  
  225. *=================================================
  226. *  Entry to program - called by & vector:
  227. *  Determine which routine is called and
  228. *    jump to it.
  229. *=================================================
  230.  
  231. START
  232.           PHA
  233.           JSR CHRGET     ;advance TXTPTR
  234.           PLA
  235.           CMP #$80       ;END token
  236.           BNE NOTEND
  237.  
  238. * EXIT (restore old ampersand vector and pointers)
  239.  
  240. EXIT      LDY #1
  241. :1        LDA STASH,Y
  242.           STA AMPV+1,Y
  243.           DEY
  244.           BPL :1
  245.           LDA #8         ;set start of BASIC to $801
  246.           STA TXTTAB+1
  247.           LDA #0
  248.           STA TXTTAB
  249.           STA ERRFLG     ;kill ONERR
  250.           LDY #2
  251. :2        STA (TXTTAB),Y ;zero out first line
  252.           DEY
  253.           BPL :2
  254.           INC TXTTAB
  255.           RTS            ;end restore machine
  256.  
  257. * Branch to routine called by BASIC:
  258.  
  259. NOTEND
  260.           CMP #$E3       ;LEN token
  261.           BEQ GETLEN
  262.           CMP #$A8       ;STORE token
  263.           BNE :1
  264.           JMP STORE
  265. :1        CMP #$84       ;INPUT token
  266.           BNE :2
  267.           JMP STRINGS
  268. :2        CMP #$83       ;DATA token
  269.           BNE :3
  270.           JMP DATA
  271. :3        CMP #$85       ;DEL token
  272.           BNE :4
  273.           JMP DEL
  274. :4        CMP #$D4       ;ABS token
  275.           BNE :5
  276.           JMP STRIP
  277. :5        CMP #$D6       ;FRE token
  278.           BNE :6
  279.           JMP MEMORY
  280. :6
  281.           JMP MEMMOV     ;if not one of the above,
  282.                          ;  see if it's "MOVE"
  283.  
  284. *---------------------------------------------------------
  285. * GETLEN (Get start and end address of a shape)
  286. * Called directly from BASIC for extract-a-shape function.
  287. * Also used by ML add and delete routines
  288. *
  289. *  & LEN shapenum
  290. *  returns:  shape start address at PEEK (6)
  291. *            shape end address at PEEK (8)
  292. *---------------------------------------------------------
  293.  
  294. GETLEN    JSR GETBYT     ;get number of shape to find
  295. GETLEN1   TXA            ;enter here from add or delete
  296.           LDX #0
  297.           ASL            ;double shape # for index
  298.           STA PTR1
  299.           BCC :1
  300.           INX
  301. :1        STX PTR1+1     ;move index into PTR1
  302.           CLC
  303.           LDA SHAPE      ;move start address of offset to
  304.           ADC PTR1       ; desired shape into PTR
  305.           STA PTR
  306.           LDA SHAPE+1
  307.           ADC PTR1+1
  308.           STA PTR+1
  309.           CLC
  310.           LDY #0
  311.           LDA (PTR),Y    ;move start address of desired
  312.           ADC SHAPE      ; shape into PTR1 and into PTR
  313.           STA PTR1
  314.           TAX
  315.           INY            ;Y = 1
  316.           LDA (PTR),Y
  317.           ADC SHAPE+1
  318.           STA PTR1+1
  319.           STA PTR+1
  320.           STX PTR
  321.           DEY            ;Y = 0
  322. :LOOP     LDA (PTR1),Y   ;scan through data until
  323.           BEQ :END       ; zero byte found
  324.           INC PTR1
  325.           BNE :LOOP
  326.           INC PTR1+1
  327.           BNE :LOOP      ;always
  328. :END      LDY #3
  329. :2        LDA PTR,Y
  330.           STA ADRSAVE1,Y
  331.           DEY
  332.           BPL :2
  333.  
  334.           SEC            ;put lngth of shape into LENGTH1
  335.           LDA PTR1
  336.           SBC PTR
  337.           STA LENGTH1
  338.           LDA PTR1+1
  339.           SBC PTR+1
  340.           STA LENGTH1+1
  341.           INC LENGTH1
  342.           BNE :3
  343.           INC LENGTH1+1
  344.  
  345. :3        RTS            ;end find LEN of shape
  346.  
  347.  
  348. *--------------------------------------------------------
  349. * STORE (add one shape to main table from aux table):
  350. *
  351. * & STORE shapenum AT END (add a shape)
  352. *     or
  353. * & STORE shapenum AT shapenum (insert a shape)
  354. *
  355. * returns:  PEEK (6) = 0 if successful
  356. *           PEEK (6) = 1 if memory conflice
  357. *--------------------------------------------------------
  358.  
  359. STORE     JSR GETBYT     ;get number of shape to move
  360.           STX FROMNUM    ;save shape number
  361.  
  362.           JSR GETLEN1    ;get address & length of shape
  363.           JSR MOVPTRS    ;move to ADRSAVE2, etc.
  364.  
  365.           LDA #$C5       ;check for AT token
  366.           JSR SYNCHR
  367.  
  368.           JSR SWITCH     ;switch pointers for GETLEN
  369.  
  370.           JSR OURADR     ;get params of where to add
  371.  
  372.           JSR UNSWITCH   ;restore table pointers
  373.  
  374. * Check whether there's room to add shape:
  375.  
  376.           CLC
  377.           LDA END1       ;add length of shape to
  378.           ADC LENGTH2    ; end address of table
  379.           PHA
  380.           LDA END1+1
  381.           ADC LENGTH2+1
  382.           STA PTR+1
  383.           PLA            ;compare proposed new end addr
  384.           CMP SHAPE      ; with start addr of aux table
  385.           LDA PTR+1
  386.           SBC SHAPE+1
  387.           BCC :OK        ;continue if no collision
  388.           LDA #1
  389.           STA EFLG       ;else set error flag and
  390.           RTS            ; return without doing
  391.  
  392.  
  393. :OK       LDA SHAPE1     ;new shape table address =
  394.           STA PTR1       ; old address minus 2
  395.           SEC
  396.           SBC #2         ;move new table index address
  397.           STA SHAPE1     ; into SHAPE1
  398.           STA PTR        ; and into PTR
  399.           LDA SHAPE1+1
  400.           STA PTR1+1     ;old index address into PTR1
  401.           SBC #0
  402.           STA SHAPE1+1
  403.           STA PTR+1
  404.  
  405.           LDY #0
  406.           STY A1H
  407.           LDA (PTR1),Y
  408.           CLC
  409.           ADC #1         ;add 1 shape to number of
  410.           STA (SHAPE1),Y ; shapes in table index
  411.           STA SHAPES
  412.           INY
  413.           LDA (PTR1),Y   ;move second byte of index
  414.           STA (SHAPE1),Y ; down 2 addresses
  415.           INY            ;Y = 2
  416.           STY A1L
  417.  
  418.           LDX TONUM
  419.  
  420. :OFFSET   CLC
  421.           LDA (PTR1),Y   ;get shape address offset
  422.           ADC A1L        ;increase for new shape added
  423.           STA (PTR),Y    ;store it 2 bytes lower in index
  424.           INY            ;Y = 3
  425.           LDA (PTR1),Y
  426.           ADC A1H
  427.           STA (PTR),Y
  428.           DEY            ;Y = 2
  429.           JSR INCPTRS
  430.           JSR INCPTRS
  431.           DEX
  432.           BNE :OFFSET
  433.  
  434.  
  435.           BIT MODE       ;ADD or INSERT?
  436.           BPL :INSERT
  437.  
  438. * Make new offset if shape is added at end of table:
  439.  
  440.           CLC
  441.           LDA LENGTH1
  442.           ADC #2
  443.           STA A1L
  444.           LDA LENGTH1+1
  445.           ADC #0
  446.           STA A1H
  447.           LDX #1
  448.           BNE :LOOP      ;branch always
  449.  
  450. * Fix offsets if shape is inserted:
  451.  
  452. :INSERT   SEC
  453.           LDA SHAPES
  454.           SBC TONUM
  455.           TAX
  456.           CLC
  457.           LDA #2
  458.           ADC LENGTH2
  459.           STA A1L
  460.           LDA #0
  461.           ADC LENGTH2+1
  462.           STA A1H
  463. :LOOP     CLC
  464.           LDA (PTR),Y
  465.           ADC A1L
  466.           STA (PTR),Y
  467.           INY
  468.           LDA (PTR),Y
  469.           ADC A1H
  470.           STA (PTR),Y
  471.           DEY
  472.           JSR INCPTR
  473.           JSR INCPTR
  474.           DEX
  475.           BNE :LOOP
  476.  
  477.           BIT MODE       ;ADD or INSERT?
  478.           BMI :ADDEND
  479.  
  480. * Open up space to insert shape:
  481.  
  482.           CLC
  483.           LDA ADRSAVE1
  484.           STA LOWTR      ;start of block to move
  485.           ADC LENGTH2
  486.           STA A4L        ;destination address
  487.           LDA ADRSAVE1+1
  488.           STA LOWTR+1
  489.           ADC LENGTH2+1
  490.           STA A4H
  491.  
  492.           LDA END1       ;end of block to move
  493.           LDY END1+1
  494.           STA HIGHTR
  495.           INC HIGHTR
  496.           BNE :2
  497.           INY
  498. :2        STY HIGHTR+1
  499.           JSR HIGHER     ;go move part of table
  500.  
  501.  
  502.  
  503. * Move new shape into main table:
  504.  
  505.           LDA ADRSAVE1   ;destination address
  506.           LDY ADRSAVE1+1
  507.           BNE :4         ;always
  508.  
  509. :ADDEND   LDX ADREND1    ;dest addr for add at end
  510.           LDY ADREND1+1
  511.           INX
  512.           BNE :3
  513.           INY
  514. :3        TXA
  515.  
  516. :4        STA A4L
  517.           STY A4H
  518.  
  519.           LDA ADRSAVE2   ;start address
  520.           LDY ADRSAVE2+1
  521.           STA A1L
  522.           STY A1H
  523.  
  524.           LDA ADREND2    ;end address
  525.           LDY ADREND2+1
  526.           STA A2L
  527.           STY A2H
  528.  
  529.           LDY #0
  530.           JSR MOVE
  531.  
  532. :UPDATE   CLC            ;update end of table address
  533.           LDA LENGTH2
  534.           ADC END1
  535.           STA END1
  536.           LDA LENGTH2+1
  537.           ADC END1+1
  538.           STA END1+1
  539.  
  540.           LDA #0
  541.           STA EFLG       ;clear error flag
  542. STOREND   RTS            ;end add one entry
  543.  
  544.  
  545. *---------------------------------------
  546. * SUBROUTINES (used by STORE and DEL):
  547. *---------------------------------------
  548.  
  549. SWITCH    LDX #1
  550. :1        LDA SHAPE,X    ;move main shape table address
  551.           STA TEMP,X     ; into SHAPE for GETLEN routine
  552.           LDA SHAPE1,X
  553.           STA SHAPE,X
  554.           DEX
  555.           BPL :1
  556.           RTS
  557.  
  558. UNSWITCH  LDX #1
  559. :1        LDA TEMP,X
  560.           STA SHAPE,X
  561.           DEX
  562.           BPL :1
  563.           RTS
  564.  
  565. MOVPTRS   LDX #5         ;save address & length
  566. :1        LDA ADRSAVE1,X
  567.           STA ADRSAVE2,X
  568.           DEX
  569.           BPL :1
  570.           RTS
  571.  
  572. OURADR    LDY #0
  573.           LDA (SHAPE1),Y
  574.           STA SHAPES     ;number shapes in main table
  575.           STY MODE
  576.           JSR CHRGOT     ;get loc of shape to add or DEL
  577.           CMP #$80       ;END token ?
  578.           BNE :1         ;no, go get a shape number
  579.           STA MODE       ;yes, set MODE for end (A = $80)
  580.           INC MODE
  581.           JSR CHRGET     ;advance TXTPTR and
  582.           LDA SHAPES     ; use number of shapes in table
  583.           TAX
  584.           BNE :2
  585.  
  586.           LDA END1       ;use END1 if starting new table
  587.           LDY END1+1
  588.           STA ADRSAVE1
  589.           STA ADREND1
  590.           STY ADRSAVE1+1
  591.           STY ADREND1+1
  592.           LDY #0
  593.           STY LENGTH1
  594.           STY LENGTH1+1
  595.           RTS
  596.  
  597. :1        JSR GETBYT
  598. :2        STX TONUM      ;place to move shape to or from
  599.           JMP GETLEN1    ;get move-to address and RTS
  600.  
  601. INCPTRS
  602.           INC PTR1
  603.           BNE INCPTR
  604.           INC PTR1+1
  605. INCPTR    INC PTR
  606.           BNE :1
  607.           INC PTR+1
  608. :1        RTS
  609.  
  610. *---------------------------------------------------------
  611. * DEL (Delete one shape):
  612. *
  613. * & DEL shapenum
  614. *---------------------------------------------------------
  615.  
  616. DEL       JSR SWITCH     ;move main table adr into SHAPE
  617.           JSR OURADR     ;get info on shape to DEL
  618.           JSR MOVPTRS    ;save it at ADRSAVE2, etc.
  619.  
  620. * Get length of segment to delete:
  621.  
  622.           LDX TONUM      ;get info on next higher shape
  623.           CPX SHAPES     ; or end of table
  624.           BNE :1A        ;branch if not at end
  625.           DEC MODE       ;else set MODE negative
  626.           SEC            ;and use end of table info
  627.           LDA END1
  628.           SBC ADRSAVE2
  629.           STA LENGTH1
  630.           LDA END1+1
  631.           SBC ADRSAVE2+1
  632.           STA LENGTH1+1
  633.           CLC
  634.           BCC :1B
  635.  
  636. :1A       INX            ;point at next higher shape
  637.           JSR GETLEN1    ;get info on next higher shape
  638.           SEC            ;calculate length to delete
  639.           LDA ADRSAVE1
  640.           SBC ADRSAVE2
  641.           STA LENGTH1
  642.           LDA ADRSAVE1+1
  643.           SBC ADRSAVE2+1
  644.           STA LENGTH1+1
  645.  
  646. :1B       JSR UNSWITCH   ;restore SHAPE pointer
  647.  
  648. * Get address of index to last shape:
  649.  
  650.           LDX #0
  651.           LDA SHAPES
  652.           ASL            ;double # of shapes for index
  653.           BCC :1
  654.           INX
  655. :1        CLC
  656.           ADC SHAPE1
  657.           STA PTR
  658.           TXA
  659.           ADC SHAPE1+1
  660.           STA PTR+1
  661.           SEC            ;(PTR1) = (PTR - 2)
  662.           LDA PTR
  663.           SBC #2
  664.           STA PTR1
  665.           LDA PTR+1
  666.           SBC #0
  667.           STA PTR1+1
  668.  
  669. * Calculate offset for shape deleted if not at END:
  670.  
  671.           LDY #0         ;subtract start of this shape
  672.           CLC            ; from start of next shape
  673.           LDA LENGTH1
  674.           ADC #2
  675.           STA A1L
  676.           LDA LENGTH1+1
  677.           ADC #0
  678.           STA A1H
  679.  
  680.           LDA SHAPES
  681.           BIT MODE       ;delete from END ?
  682.           BMI :3         ;yes
  683.  
  684.  
  685.           SEC            ;calculate # of shapes above
  686.           SBC TONUM      ;shape to be deleted
  687.  
  688.           TAX            ;# of shapes above into X
  689.           DEX
  690.           BEQ :3A        ;branch if next to last
  691.  
  692. * Decrement all indices above deleted shape:
  693.  
  694. :LOOP     SEC
  695.           LDA (PTR),Y    ;get original offset
  696.           SBC A1L        ;subtract for deleted shape
  697.           STA (PTR),Y    ;put back in same place
  698.           INY            ;then do the hi byte
  699.           LDA (PTR),Y
  700.           SBC A1H
  701.           STA (PTR),Y
  702.           DEY
  703.           JSR DECPTRS
  704.           JSR DECPTRS
  705.           DEX
  706.           BNE :LOOP      ;loop if not finished
  707.  
  708. * Fix offsets for shapes below deleted shape
  709. *   (Subtract #2 from each offset and move each
  710. *    offset up one position in table):
  711.  
  712. :3A       INC TONUM
  713.  
  714. :3        LDX TONUM
  715.           DEX
  716. :LOOP1    SEC
  717.           LDA (PTR1),Y
  718.           SBC #2
  719.           STA (PTR),Y
  720.           INY
  721.           LDA (PTR1),Y
  722.           SBC #0
  723.           STA (PTR),Y
  724.           DEY
  725.           JSR DECPTRS
  726.           JSR DECPTRS
  727.           DEX
  728.           BNE :LOOP1     ;loop until finished
  729.  
  730.           BIT MODE
  731.           BMI :DECNUM    ;branch if DEL at END
  732.  
  733. * Move block of table down if shape deleted from middle:
  734.  
  735.           LDA ADRSAVE2   ;move-to address
  736.           LDY ADRSAVE2+1
  737.           STA A4L
  738.           STY A4H
  739.  
  740.           LDA ADRSAVE1   ;start of block to move
  741.           LDY ADRSAVE1+1
  742.           STA A1L
  743.           STY A1H
  744.  
  745.           LDA END1       ;end of block to move
  746.           LDY END1+1
  747.           STA A2L
  748.           STY A2H
  749.  
  750.           LDY #0
  751.           JSR MOVE       ;use monitor move routine
  752.  
  753. * Decrement number of shapes:
  754.  
  755. :DECNUM   DEC SHAPES
  756.           LDA SHAPES
  757.           STA (PTR),Y    ;poke new # into table header
  758.           INY
  759.           LDA (PTR1),Y   ;move next byte intact-sometimes
  760.           STA (PTR),Y    ; used as a type indicator
  761.  
  762. * Decrease length of table:
  763.  
  764.           SEC
  765.           LDA END1
  766.           SBC LENGTH1
  767.           STA END1
  768.           LDA END1+1
  769.           SBC LENGTH1+1
  770.           STA END1+1
  771.  
  772. * Fix start address of table:
  773.  
  774.           CLC
  775.           LDA SHAPE1
  776.           ADC #2
  777.           STA SHAPE1
  778.           LDA SHAPE1+1
  779.           ADC #0
  780.           STA SHAPE1+1
  781.  
  782.           RTS            ;end DEL one shape
  783.  
  784. *-------------------------------
  785. * SUBROUTINES (Used by DEL):
  786. *-------------------------------
  787.  
  788. DECPTRS   LDA PTR1
  789.           BNE :1
  790.           DEC PTR1+1
  791. :1        DEC PTR1
  792. DECPTR    LDA PTR
  793.           BNE :1
  794.           DEC PTR+1
  795. :1        DEC PTR
  796.           RTS
  797.  
  798. *---------------------------------------------------------
  799. * MEMORY (find how many shapes fit below hi-res page):
  800. *   Enter with start address of table in $E8,E9
  801. *              end address of table in $8,9
  802. *   & FRE
  803. *   returns:  PEEK(6) = number of shapes that
  804. *               will fit below $4000
  805. *---------------------------------------------------------
  806.  
  807. MEMORY
  808.  
  809. :1        LDA #$40       ;check at $4000
  810.           STA PTR2+1
  811.           LDY #0
  812.           STY PTR2
  813.           LDA (SHAPE),Y  ;get number of shapes
  814.           STA TONUM      ;and save it
  815.  
  816.           LDA SHAPE      ;move start address of table
  817.           LDX SHAPE+1    ; into PTR
  818.           STA PTR
  819.           STX PTR+1
  820.           LDX #0         ;use X as a counter
  821.  
  822. :LOOP     JSR INCPTR     ;point at next shape offset
  823.           JSR INCPTR
  824.  
  825.           CLC
  826.           LDA (PTR),Y    ;calculate address of
  827.           ADC SHAPE      ; next shape in table
  828.           STA PTR2
  829.           INY
  830.           LDA (PTR),Y
  831.           ADC SHAPE+1
  832.           DEY
  833.           CMP PTR2+1     ;has hi byte reached limit?
  834.           BLT :2         ;no, increment & continue
  835.           BGE :3         ;yes, exit
  836.  
  837. :2        INX
  838.           CPX TONUM      ;reached last shape ?
  839.           BLT :LOOP      ;no, back thru loop
  840.           LDA PTR1+1     ;check end of table
  841.           CMP PTR2+1     ; for collision
  842.           BGE :3         ;last shape doesn't fit
  843.           INX
  844.  
  845. :3        DEX            ;we've gone one too far
  846.           STX EFLG       ;mark intact valid shape
  847.           RTS            ;and return to caller
  848.  
  849. *---------------------------------------------------------
  850. * Jump to monitor move routine (to move down)
  851. *   or to BASIC BLTU routine (to move up)
  852. * SYNTAX:
  853. *  & MOVE,[old start adr],[old end adr] TO [new start adr]
  854. *---------------------------------------------------------
  855.  
  856. MEMMOV    EQU *
  857.           CMP #'M
  858.           BEQ :1
  859.           JMP SYNERR
  860. :1        LDA #'O
  861.           JSR SYNCHR
  862.           LDA #'V
  863.           JSR SYNCHR
  864.           LDA #'E
  865.           JSR SYNCHR
  866.           JSR CHKCOM
  867.           JSR FRMNUM     ;get start address
  868.           JSR GETADR
  869. :A        LDA LINNUM     ;LINNUM has old start address
  870.           STA A1L        ;store it for move down
  871.           PHA            ;push it for move up
  872.           LDA LINNUM+1
  873.           STA A1H
  874.           PHA
  875. *
  876.           JSR CHKCOM     ;next parameter -
  877.           JSR FRMNUM     ; get end address of range
  878.           JSR GETADR
  879. :B        LDA LINNUM
  880.           STA A2L
  881.           PHA
  882.           LDA LINNUM+1
  883.           STA A2H
  884.           PHA
  885. *
  886.           LDA #$C1       ;check for "TO" token
  887.           JSR SYNCHR
  888.  
  889.           JSR FRMNUM     ;get destination address
  890.           JSR GETADR
  891.           LDA LINNUM
  892.           STA A4L
  893.           LDA LINNUM+1
  894.           STA A4H
  895. *
  896.           PLA            ;recover old end address
  897.           STA HIGHTR+1   ; store it for MOVEUP
  898.           PLA
  899.           STA HIGHTR
  900.           INC HIGHTR
  901.           BNE :2
  902.           INC HIGHTR+1
  903.  
  904. :2        PLA            ;recover old start address
  905.           STA LOWTR+1    ; store it for MOVEUP
  906.           PLA
  907.           STA LOWTR
  908.  
  909. * Decide whether move up or down:
  910.  
  911.           CMP LINNUM
  912.           LDA LOWTR+1
  913.           SBC LINNUM+1
  914.           BCS LOWER
  915.  
  916. * Move up in memory:
  917.  
  918. HIGHER    SEC            ;get length of segment
  919.           LDA HIGHTR     ; to move
  920.           SBC LOWTR
  921.           TAY
  922.           LDA HIGHTR+1
  923.           SBC LOWTR+1
  924.           TAX
  925.           TYA            ;low byte -> A
  926.           CLC            ;add length to destination addr
  927.           ADC A4L
  928.           STA HIGHDS
  929.           TXA
  930.           ADC A4H
  931.           STA HIGHDS+1
  932.           JMP MOVEUP
  933.  
  934. * Move down in memory:
  935.  
  936. LOWER     LDY #0
  937.           JMP MOVE       ;monitor memory move
  938.  
  939.  
  940. *----------------------------------------------------
  941. * & DATA:
  942. *   Determine whether a table is a shape table
  943. *     or a vector table.
  944. *     Return with PEEK (6) = 1 if vector
  945. *                          = 0 if shape
  946. *  Assumption:  a vector shape (with no index) will
  947. *   not have two or more non-consecutive zero bytes
  948. *----------------------------------------------------
  949.  
  950. DATA
  951.           LDY #0
  952.           STY COUNTER
  953.           STY MODE
  954.           STY EFLG       ;PEEK(6) = 0
  955. :LOOP     LDA (PTR1),Y   ;get next byte
  956.           BEQ :INCCTR    ;branch if it's zero
  957.           BIT MODE       ;non-zero following zero ?
  958.           BPL :LOOP1     ;no, continue
  959.           INC MODE       ;yes, clear MODE and continue
  960. :LOOP1    INC PTR1
  961.           BNE :1
  962.           INC PTR1+1
  963.  
  964. :1        LDA PTR1+1     ;check for end of table
  965.           CMP PTR2+1
  966.           BLT :LOOP
  967.           LDA PTR1
  968.           CMP PTR2
  969.           BLT :LOOP
  970.           BEQ :LOOP
  971.  
  972.           INC EFLG       ;PEEK(6)  = 1 if vector table
  973.           RTS            ;exit to caller
  974.  
  975. :INCCTR   BIT MODE       ;was preceding byte also 0 ?
  976.           BMI :LOOP1     ;yes
  977.           DEC MODE       ;set MODE = #$FF
  978.           INC COUNTER
  979.           LDA COUNTER
  980.           CMP #2
  981.           BLT :LOOP1
  982.           RTS            ;PEEK(6) = 0 if shape table
  983.                          ;exit to caller
  984.  
  985. *------------------------------------------------
  986. * STRIP filename routine:
  987. *   & ABS sexpr1,sexpr2
  988. *   returns "pure" filename in sexpr2, less
  989. *     any ProDOS prefix or slot/drive parameter
  990. *------------------------------------------------
  991.  
  992. STRIP     JSR PTRGET     ;get name of first string
  993.           STA PTR1
  994.           STY PTR1+1
  995.           LDY #0
  996.           LDA (PTR1),Y   ;get length of string
  997.           STA LENGTH1
  998.           TAX
  999.           INY
  1000.           LDA (PTR1),Y   ;get address of string
  1001.           STA PTR
  1002.           STA A1L
  1003.           INY
  1004.           LDA (PTR1),Y
  1005.           STA PTR+1
  1006.           STA A1H
  1007.           LDY #0
  1008.  
  1009.           STY COUNTER
  1010.  
  1011. :LOOP     LDA (PTR),Y    ;get next char of string
  1012.           JSR INCPTR
  1013.           CMP #'/        ;is it a slash?
  1014.           BNE :CHKCOM
  1015.           STX LENGTH1
  1016.           DEC LENGTH1
  1017.           LDA PTR
  1018.           STA A1L
  1019.           LDA PTR+1
  1020.           STA A1H
  1021.           CLC
  1022.           BCC :1         ;branch always
  1023.  
  1024. :CHKCOM   CMP #',        ;is it a comma ?
  1025.           BNE :1
  1026.           STX LENGTH2
  1027.           SEC
  1028.           LDA LENGTH1
  1029.           SBC LENGTH2
  1030.           TAX
  1031.           CLC
  1032.           BCC :END
  1033.  
  1034. :1        DEX
  1035.           BNE :LOOP
  1036.           LDX LENGTH1
  1037.  
  1038. :END
  1039.           STX LENGTH2
  1040.           LDA #$0D       ;RETURN
  1041.           STA BUFFER,X
  1042.           DEX
  1043.           LDY #0
  1044. :LUP      LDA (A1L),Y
  1045.           STA BUFFER,Y
  1046.           INY
  1047.           DEX
  1048.           CPX #$FF
  1049.           BNE :LUP
  1050.  
  1051.           JSR CHKCOM     ;read a comma
  1052.           JSR PTRGET     ;get adr of second variable
  1053.           LDX LENGTH2
  1054.           JMP EXIT1
  1055.  
  1056. *------------------------------------------------------
  1057. * STRING input routine:
  1058. *   & INPUT sexpr [,aexpr]
  1059. * optional second parameter limits length of input.
  1060. * if length is defined, routine also writes
  1061. *  them on text page 2
  1062. * returns:  string input in sexpr
  1063. *            PEEK(6) = 1 if user pressed [ESC] else =0
  1064. * [DELETE] key works like backspace
  1065. *------------------------------------------------------
  1066.  
  1067. STRINGS   JSR PTRGET     ;get name of variable
  1068.           JSR CHKSTR     ;make sure it's a string
  1069.           LDY #0
  1070.           STY MODE
  1071.           LDX #19        ;store pgm's [ESC] prompt
  1072. :1B       LDA $7D7,X
  1073.           STA STASH1,X
  1074.           DEX
  1075.           BPL :1B
  1076.  
  1077.           LDA #$FE
  1078.           STA MAX        ;default max input length
  1079.           JSR CHRGOT     ;end of input params?
  1080.           BEQ :1         ;yes, branch
  1081.           JSR CHKCOM
  1082.           JSR GETBYT     ;get max allowable length
  1083.           INX
  1084.           STX MAX
  1085.           DEC MODE       ;MODE = #$FF
  1086.           LDA #$60
  1087.           STA $B72
  1088.  
  1089. :1        LDX #$00       ;zero X reg
  1090.           STX EFLG       ;zero ESC flag
  1091.           JSR RDKEY      ;get first char input
  1092.           CMP #$8D       ;[RETURN] ?
  1093.           BEQ :ADDINP    ;yes, process it
  1094.           PHA            ;else save it
  1095.           JSR CLREOL     ;and clear line on screen
  1096.           PLA
  1097.           JMP :INPUT1
  1098. *
  1099. :NOTCR    JSR COUT       ;print character
  1100.           BIT MODE
  1101.           BPL :1A
  1102.           STA $B72,X     ;print also on page 2
  1103.           CPX MAX
  1104.           BGE :1A
  1105.           LDA #$60       ;flashing space
  1106.           STA $B73,X     ; as a cursor on page 2
  1107. :1A       INX
  1108.           CPX MAX        ;buffer full?
  1109.           BLT :INPUT     ;no, go get more input
  1110.  
  1111. :BCKSPC   TXA            ;full buffer or back arrow key
  1112.           BEQ :INPUT     ;branch if at beginning
  1113.           JSR ERASE      ;erase one character
  1114.           BNE :INPUT     ;branch if not at beginning
  1115.           JSR FIXPRMPT   ;else restore [ESC] prompt
  1116.  
  1117. :INPUT    JSR RDKEY
  1118. :INPUT1   CMP #$9B       ;[ESC] ?
  1119.           BNE :4         ;no, continue
  1120.           CPX #0         ;at beginning of input?
  1121.           BEQ :3         ;yes, set flag and return
  1122.           JSR FIXPRMPT   ;no, restore [ESC] message and
  1123. :2        JSR ERASE      ; erase to beginning of input
  1124.           BNE :2
  1125.           BEQ :INPUT
  1126.  
  1127. :3        INC EFLG       ;set ESC flag and
  1128.           BNE :CR        ; return to BASIC
  1129.  
  1130. :4        CMP #$88       ;[<--]
  1131.           BEQ :BCKSPC
  1132.           CMP #$FF       ;[DELETE]
  1133.           BEQ :BCKSPC
  1134.           CMP #$8D       ;[RETURN]
  1135.           BEQ :ADDINP
  1136.           CMP #$A0       ;reject CONTROL characters
  1137.           BLT :INPUT
  1138.           CPX #0
  1139.           BNE :ADDINP
  1140.           JSR OURPRMPT   ;display [ESC] message
  1141.  
  1142. :ADDINP   STA BUFFER,X
  1143.           CMP #$8D
  1144.           BNE :NOTCR
  1145. :CR       LDA #$8D
  1146.           JSR COUT
  1147. :EXIT     LDY EFLG       ;DON'T CHANGE STRING
  1148.           BEQ EXIT1      ; IF EXITING VIA [ESC]
  1149.           RTS
  1150. EXIT1     LDY #$00
  1151.           TXA
  1152.           STA ($83),Y
  1153.           STA $1E
  1154.           INY
  1155.           LDA #$00
  1156.           STA ($83),Y
  1157.           INY
  1158.           LDA #$02
  1159.           STA ($83),Y
  1160.           JSR GDBUFS
  1161.           LDA $1E
  1162.           JSR STRSPA
  1163.           LDY #$02
  1164. :LOOP     LDA DSCTMP,Y
  1165.           STA ($83),Y
  1166.           DEY
  1167.           BPL :LOOP
  1168.           LDX #$00
  1169.           LDY #$02
  1170.           LDA DSCTMP
  1171.           JMP MOVSTR
  1172.  
  1173. ERASE     LDA #$88
  1174.           JSR COUT1
  1175.           LDA #$A0       ;print " ";
  1176.           JSR COUT1
  1177.           BIT MODE
  1178.           BPL :6
  1179.           STA $B72,X
  1180.           LDA #$60
  1181.           STA $B71,X
  1182. :6        LDA #$88
  1183.           JSR COUT1
  1184.           DEX
  1185.           RTS            ;end erase one char
  1186.  
  1187. OURPRMPT  LDY #20        ;print "ERASE ENTRY"
  1188.           PHA            ;save entered char
  1189. :LOOP     LDA PRMPT,Y
  1190.           STA $7D7,Y
  1191.           STA $BD7,Y
  1192.           DEY
  1193.           BPL :LOOP
  1194.           PLA
  1195.           RTS
  1196.  
  1197. FIXPRMPT  LDY #19        ;restore pgm's [ESC] prompt
  1198.           PHA
  1199. :LOOP     LDA STASH1,Y
  1200.           STA $7D7,Y
  1201.           STA $BD7,Y
  1202.           DEY
  1203.           BPL :LOOP
  1204.           PLA
  1205.           RTS
  1206.  
  1207. PRMPT     ASC "ERASE ENTRY"
  1208.           ASC "          " ;10 spaces
  1209.           HEX 000000
  1210.  
  1211.           ORG
  1212. END
  1213.